import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router);

// 2. 定义一些路由
// 每个路由都需要映射到一个组件。
const routes = [
  { path: '/', redirect: '/home/goodlist' },  //重定向}
  {
    path: '/home', name: 'Home', component: () => import('@view/Home/home.vue'),
    children: [
      {
        path: 'goodlist',
        component: () => import('@/view/Home/children/list.vue')
      },
      {
        path: 'goodDetail/:productId',
        component: () => import('@/view/Home/children/goodDetail.vue')
      }
    ]
  },
  { path: '/type', name: 'Type', component: () => import('@view/Type/type.vue') },
  { path: '/cart', name: 'Cart', component: () => import('@view/Cart/cart.vue') },
  // 订单
  {
    path: '/order', component: () => import("@/view/Order/index.vue"),
    children: [
      { path: 'preOrder', component: () => import('@view/Order/children/preOrder.vue') },
      { path: 'orderList', component: () => import('@view/Order/children/orderList.vue') },

      { path: 'pay', component: () => import('@view/Order/children/pay.vue') },
    ]
  },

  { path: '/my', name: 'My', component: () => import('@view/My/my.vue') },
  { path: '/login', component: () => import('@view/Login/login.vue') },
  { path: '/logout', component: () => import('@view/Login/logout.vue') },
  // 活动页面
  {
    path: '/activity', component: () => import('@/view/Activity/index'),
    children: [
      { path: 'seckill', component: () => import("@/view/Activity/children/seckill.vue") },
      { path: 'collage', component: () => import("@/view/Activity/children/Collage.vue") },
      { path: 'coupon', component: () => import("@/view/Activity/children/coupon.vue") },
      { path: 'useCoupon', component: () => import("@/view/Activity/children/useCoupon.vue") },
      { path: 'collection', component: () => import("@/view/Activity/children/seckill.vue") },
      { path: 'records', component: () => import("@/view/Activity/children/seckill.vue") },
    ]
  },
  // 客服
  { path: '/custCare', component: () => import("@/view/custCare/index.vue") },
  {
    path: '/address', component: () => import("@/view/Address/index.vue"),
    children: [
      { path: 'list', component: () => import("@/view/Address/children/list") },
      { path: 'add', component: () => import("@/view/Address/children/add") },
      { path: 'edit', component: () => import("@/view/Address/children/edit") },
    ]
  },
  { path: '/demo', name: 'Demo', component: () => import('@view/Demo/demo.vue') },
  { path: '/demo2', name: 'Demo2', component: () => import('@view/Demo/demo2.vue') },
  // { path: '/404', name: 'NotFound', component: () => import('@view/NotFound/notFound.vue') },
  { path: '/:pathMatch(.*)', component: () => import('@view/NotFound/notFound.vue') },
]

// 创建路由实例并传递routes配置
const router = new Router({
  //使用hash会加上#
  // history: createWebHashHistory(),
  // mode: 'history',
  mode: 'hash',
  routes
})

// 导出
export default router;